package com.efesco.system;

import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.common.*;
import com.efesco.common.Tools;

/**
 * functionRight_functionRightDatasetListener
 */
public class functionRight_functionRightDatasetListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset)
     throws Exception {
  	String superFunctionId=Tools.toStr(dataset.parameters().getString("super_function_id"));
  	String employeeId=Tools.toStr(dataset.parameters().getString("employee_id"));
  	String sql="";
  	if (!superFunctionId.equals("") &&  !superFunctionId.equals("null"))  {
  		sql="select sf.*,1 isChecked from s_function sf,s_function_right tr,s_user u "+
			"where u.for_employee_id="+employeeId+" and sf.function_id=tr.function_id "+  
			"and tr.user_id=u.user_id and sf.super_function_id="+superFunctionId+ 
			" union "+ 
			"select sf.*,0 isChecked from s_function sf where sf.super_function_id="+superFunctionId+ 
			" and sf.function_id not in "+ 
			"(select function_id from s_function_right fr,s_user u where fr.user_id=u.user_id "+ 
			"and u.for_employee_id="+employeeId+" )";
  	}
  	else  {
  		sql="select sf.*,1 isChecked from s_function sf,s_function_right tr,s_user u "+
			"where u.for_employee_id="+employeeId+" and sf.function_id=tr.function_id "+  
			"and tr.user_id=u.user_id and sf.super_function_id is null "+ 
			" union "+ 
			"select sf.*,0 isChecked from s_function sf where sf.super_function_id is null "+ 
			" and sf.function_id not in "+ 
			"(select function_id from s_function_right fr,s_user u where fr.user_id=u.user_id "+ 
			"and u.for_employee_id="+employeeId+" )";
  	}
	SqlDataset sqlDataset=(SqlDataset)dataset;
	sqlDataset.setSql(sql);
    return true;
  }

}
